package com.alibaba.middleware.hsf.guide.serial.hessian.customcollection;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import com.taobao.hsf.com.caucho.hessian.io.AbstractHessianInput;
import com.taobao.hsf.com.caucho.hessian.io.AbstractHessianOutput;
import com.taobao.hsf.com.caucho.hessian.io.Hessian2Input;
import com.taobao.hsf.com.caucho.hessian.io.Hessian2Output;

/**
 * <pre>
 * 验证Hessian不支持自定义队列的成员变量
 * 
 * 使用Hessian序列化到临时文件，然后加以读取，无法反序列化wildCard内容
 * 
 * </pre>
 * 
 * @author weipeng2k 2015年10月8日 下午4:56:43
 */
public class HessianSerial {
    
    static File file;
    
    @BeforeClass
    public static void createFile() {
        try {
            file = File.createTempFile("hessianserial", "dat");
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    
    @Test
    public void serial() throws Exception {
        CustomList cl = new CustomList();
        cl.add("1");
        cl.add("2");
        cl.add("3");
        cl.setWildCard("wildCard");
        
        AbstractHessianOutput out = new Hessian2Output(new FileOutputStream(file));
        out.writeObject(cl);
        out.flush();
    }
    
    @Test
    public void deserial() throws Exception {
        AbstractHessianInput in = new Hessian2Input(new FileInputStream(file));
        CustomList cl = (CustomList) in.readObject();
        Assert.assertNull(cl.getWildCard());
    }
    
    @AfterClass
    public static void removeFile() {
        file.delete();
    }
}
